﻿using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Reflection;
using System.Windows.Forms;
using Bornander.UI.ListItems;
using Bornander.UI;

namespace MiniGOQO
{
    public partial class FoodForm : Form
    {

        //人均消费对应数组
        int[] AvgCost=new int[]{0,5,10,20,50,100,100000};
        //加载图片
        //Bitmap hanbao = new System.Drawing.Bitmap(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) +
        //              @"\pictures\汉堡.jpg");
        //Bitmap jichi = new System.Drawing.Bitmap(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) +
        //              @"\pictures\鸡翅.jpg");
        //Bitmap longzaibao = new System.Drawing.Bitmap(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) +
        //              @"\pictures\笼仔包.jpg");
        //Bitmap jiachangcai = new System.Drawing.Bitmap(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) +
        //              @"\pictures\家常菜.jpg");
        Bitmap binggan = new System.Drawing.Bitmap(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) +
                      @"\pictures\饼干.jpg");
        Bitmap heiqiao = new System.Drawing.Bitmap(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) +
                      @"\pictures\黑巧克力.jpg");
        Bitmap jianguo = new System.Drawing.Bitmap(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) +
                      @"\pictures\坚果.jpg");
        Bitmap nailao = new System.Drawing.Bitmap(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) +
                      @"\pictures\奶酪.jpg");
        Bitmap rougan = new System.Drawing.Bitmap(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) +
                      @"\pictures\肉干.jpg");
        Bitmap zicai = new System.Drawing.Bitmap(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) +
                      @"\pictures\四洲紫菜.jpg");
        public FoodForm()
        {
            
            //初始化窗口
            InitializeComponent();


            //首先激活首页的定时器
            DelicacesListbox.StartTimer();

            ////添加项
            //Album delicae = new Album("汉堡大特价", "美食街M记", "2009-5-1", hanbao);
            //Album delicae1 = new Album("家常菜，让你有家的感觉", "家乡小厨", "2009-4-30", jiachangcai);
            //Album delicae2 = new Album("美味鸡翅等你来~", "东门广场KFC", "2009-5-1", jichi);
            //Album delicae3 = new Album("小笼包新出炉~~", "天津狗不理", "2009-5-1", longzaibao);
            
            ////添加文章内容
            //delicae.Context = "卡耐基的一生几乎都在致力于帮助人们克服谈话和演讲中畏惧和胆怯的心理，培养勇气和信心。在戴尔·卡耐基课程开课之前，他曾作过一个调查，即让人们说说来上课的原因，以及希望从这种口才演讲训练课中获得什么。调查的结果令人吃惊，大多数人的中心愿望与基本需要都是基本一样的，他们是这样回答的：当人们要我站起来讲话时，我觉得很不自在，很害怕，使我不能清晰地思考，不能集中精力，不知道自己要说的是什么。所以，我想获得自信，能泰然自若，当众站起并能随心所欲地思考，能依逻辑次序归纳自己的思想，在公共场所或社交人士的面前侃侃而谈，富有哲理且又让人信服。";
            //delicae1.Context = "当众演说不是一门闭锁的艺术，并不象许多学校的那样容易学到知识，必须经过多年的美化声音，以及苦学修辞学多年以后才能成功。平常说话轻而易举，只要遵循一些简单的规则就行。";
            //delicae2.Context = "要想获得自信心、勇气以及能力，以便在向人们发表谈话的同时能够冷静而清晰地思考，这并不象大多数人所想象的那般困难。这就如同你打高尔夫球一样，任何人都可以发展出他潜在的能力，只要他有想要如此做的充分欲望就行。";
            //delicae3.Context = "我们可以想象自信与流畅的说话能力对于一个人有多么重要，想想因此而结交的朋友和在社交上获得的成功对于一个人的重要性，想想自己能力大增而在事业上所受的影响，可以说，它是在为我们的美好未来而辅路";
            
            //DelicacesListbox.AddItem(delicae);
            //DelicacesListbox.AddItem(delicae1);
            //DelicacesListbox.AddItem(delicae2);
            //DelicacesListbox.AddItem(delicae3);

            //添加搜索的结果
            List<Bornander.UI.Eatery> tmpSearch = Bornander.UI.XMLutil.FindFood("", 0, "");
            int TodayNum= 0;//今日推荐的显示数量
            foreach (Eatery tmp in tmpSearch)
            {
                if (TodayNum != 5)
                {
                    Album delicaes = new Album(tmp.Name, tmp.Place, tmp.Phone, tmp.Image, 1);
                    delicaes.Context = tmp.Description;
                    DelicacesListbox.AddItem(delicaes);
                }
                TodayNum++;
            }
            
            //美食大搜索选项
            FoodtypeBox.Items.Add("菜系");
            FoodtypeBox.Items.Add("饭堂");
            FoodtypeBox.Items.Add("甜品、饮品、小吃");
            FoodtypeBox.Items.Add("快餐");
            FoodtypeBox.Items.Add("烧烤");
            FoodtypeBox.Items.Add("粤菜、客家菜、潮汕菜");
            FoodtypeBox.Items.Add("川菜、湘菜");
            FoodtypeBox.Items.Add("其他菜系");
            FoodtypeBox.Items.Add("日韩料理");
            FoodtypeBox.Items.Add("西餐");
            FoodtypeBox.Items.Add("火锅");
            FoodtypeBox.Items.Add("面食");
            FoodtypeBox.Text = "菜系";

            feeBox.Items.Add("人均消费");
            feeBox.Items.Add("5元以下");
            feeBox.Items.Add("10元以下");
            feeBox.Items.Add("20元以下");
            feeBox.Items.Add("30元以下");
            feeBox.Items.Add("50元以下");
            feeBox.Items.Add("100元以下");
            feeBox.Items.Add("100元以上");
            feeBox.Text = "人均消费";

            addressBox.Items.Add("所在位置");
            addressBox.Items.Add("广大商业城");
            addressBox.Items.Add("商业南区");
            addressBox.Items.Add("商业北区");
            addressBox.Items.Add("北亭广场");
            addressBox.Items.Add("贝岗村");
            addressBox.Items.Add("北亭村");
            addressBox.Items.Add("穗石村");
            addressBox.Items.Add("南亭村");
            addressBox.Items.Add("学校内");
            addressBox.Items.Add("大学城周边");
            addressBox.Items.Add("广州市区");
            addressBox.Text = "所在位置";

            //美食活动选项
            ATSortBox.Items.Add("最新活动");
            ATSortBox.Items.Add("最多人参与");
            ATSortBox.Text = "最新活动";

            Color c1 = Color.Orange;
            Color c2 = Color.OrangeRed;
            //美食专题
            Album food1 = new Album("饼干—要好吃不要大肚腩", "思朗纤麸低糖蔬菜消化饼", "淘宝价：8.50元", binggan,c1,c2,0);
            Album food2 = new Album("黑巧克力—微苦的浓情诱惑", "韩国乐天72%黑巧克力", "淘宝价：12.00元", heiqiao, c1, c2, 0);
            Album food3 = new Album("坚果—健康原动力", "天虹开心果", "淘宝价：34.00元", jianguo, c1, c2, 0);
            Album food4 = new Album("奶酪—特别的健康好滋味", "蒙牛缔芝特熏制奶酪高级块装", "淘宝价：18.80元", nailao, c1, c2, 0);
            Album food5 = new Album("肉干—难以割舍的“肉望”", "母亲牌牛肉棒", "淘宝价：3.4元", rougan, c1, c2, 0);
            Album food6 = new Album("海苔—低脂肪的海水精华库", "四洲紫菜（50小包）", "淘宝价：23.00元", zicai, c1, c2, 0);

            FoodMixListbox.AddItem(food1);
            FoodMixListbox.AddItem(food2);
            FoodMixListbox.AddItem(food3);
            FoodMixListbox.AddItem(food4);
            FoodMixListbox.AddItem(food5);
            FoodMixListbox.AddItem(food6);

            //美食活动
            Album food11 = new Album("饼干—要好吃不要大肚腩", "思朗纤麸低糖蔬菜消化饼", "淘宝价：8.50元", binggan);
            Album food21 = new Album("黑巧克力—微苦的浓情诱惑", "韩国乐天72%黑巧克力", "淘宝价：12.00元", heiqiao);
            Album food31 = new Album("坚果—健康原动力", "天虹开心果", "淘宝价：34.00元", jianguo);
            Album food41 = new Album("奶酪—特别的健康好滋味", "蒙牛缔芝特熏制奶酪高级块装", "淘宝价：18.80元", nailao);
            Album food51 = new Album("肉干—难以割舍的“肉望”", "母亲牌牛肉棒", "淘宝价：3.4元", rougan);
            Album food61 = new Album("海苔—低脂肪的海水精华库", "四洲紫菜（50小包）", "淘宝价：23.00元", zicai);

            ActivitiesListbox.AddItem(food11);
            ActivitiesListbox.AddItem(food21);
            ActivitiesListbox.AddItem(food31);
            ActivitiesListbox.AddItem(food41);
            ActivitiesListbox.AddItem(food51);
            ActivitiesListbox.AddItem(food61);

            

        }

        private void button1_Click(object sender, EventArgs e)//搜索
        {
            foreach (Album ta in SearchListbox.Items) {//先移除所有的items
                SearchListbox.RemoveItem(ta);
            }

            //搜索条件
            string type;//菜系
            if (FoodtypeBox.Text != "菜系")
            {
                type = FoodtypeBox.Text;
            }
            else {
                type = "";
            }

            int cost = 0;//人均消费
            cost = AvgCost[feeBox.SelectedIndex];

            string address;//所在位置
            if (addressBox.Text != "所在位置")
            {
                address = addressBox.Text;
            }
            else {
                address = "";
            }

            //添加搜索的结果
            List<Bornander.UI.Eatery> tmpSearch = Bornander.UI.XMLutil.FindFood(type, cost, address);
            foreach (Eatery tmp in tmpSearch)
            {
                Album delicae = new Album(tmp.Name, tmp.Place, tmp.Phone, tmp.Image,1);
                delicae.Context = tmp.Description;
                SearchListbox.AddItem(delicae);
            }
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 0) {//首页
                DelicacesListbox.StartTimer();
                SearchListbox.StopTimer();
                ActivitiesListbox.StopTimer();
                FoodMixListbox.StopTimer();

                int iCount = menuItem1.MenuItems.Count;
                for (int i = 0; i < iCount; i++)
                {
                    this.menuItem1.MenuItems.RemoveAt(0);//移走所有选项
                }
                this.menuItem1.MenuItems.Add(this.menuItem3);//添加"美食报料"选项
                
            }
            else if (tabControl1.SelectedIndex == 1) {//美食大搜索
                DelicacesListbox.StopTimer();
                SearchListbox.StartTimer();
                ActivitiesListbox.StopTimer();
                FoodMixListbox.StopTimer();
            }
            else if (tabControl1.SelectedIndex == 2)//美食活动
            {
                DelicacesListbox.StopTimer();
                SearchListbox.StopTimer();
                ActivitiesListbox.StartTimer();
                FoodMixListbox.StopTimer();

                int iCount = menuItem1.MenuItems.Count;
                for (int i = 0; i < iCount; i++)
                {
                    this.menuItem1.MenuItems.RemoveAt(0);//移走所有选项
                }
                this.menuItem1.MenuItems.Add(this.menuItem4);//添加"发起活动"选项
                this.menuItem1.MenuItems.Add(this.menuItem5);//添加“参加活动”选项
                this.menuItem1.MenuItems.Add(this.menuItem6);//添加“排序”选项
            }
            else if (tabControl1.SelectedIndex == 3)//美食专题
            {
                DelicacesListbox.StopTimer();
                SearchListbox.StopTimer();
                ActivitiesListbox.StopTimer();
                FoodMixListbox.StartTimer();
            }
            else if (tabControl1.SelectedIndex == 4)//我的美食
            {
                DelicacesListbox.StopTimer();
                SearchListbox.StopTimer();
                ActivitiesListbox.StopTimer();
                FoodMixListbox.StopTimer();
            }
        }

        private void menuItem2_Click(object sender, EventArgs e)//返回主界面
        {
            //关闭所有定时器
            DelicacesListbox.StopTimer();
            SearchListbox.StopTimer();
            ActivitiesListbox.StopTimer();
            FoodMixListbox.StopTimer();

            MainForm mf = new MainForm();
            mf.Show();
            this.Hide();
        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            TipsForm tf = new TipsForm();
            tf.Show();
        }


    }
}